<?php
namespace Mobile\Controller;
use Think\Controller;
/**
 * 文章视图控制器
 */
class ArticleController extends CommonController{
	//文章首页视图
	public function index(){
		$id = I('get.id','','int');
		if(!$id) E('页面不存在');
		$db = M('blog');
		$art = $db->where(array('id'=>$id))->find();
		if(!$art) E('这篇文章已经在地球上消失了...');
		$field = array('id','title');
		$this->prev = $db->where(array('cid'=>$art['cid'],'id'=>array('LT',$id)))->field($field)->order('id DESC')->limit(1)->find(); 
		$this->next = $db->where(array('cid'=>$art['cid'],'id'=>array('GT',$id)))->field($field)->order('id ASC')->limit(1)->find(); 

		$this->relation = $db->where(array('cid'=>$art['cid']))->field($field)->order('time DESC')->limit(6)->select();
		$this->art = $art;

		$this->display();
	}
	
	//about页面视图
	public function about(){
		$this->display();
	}
	//评论页面视图
	public function message(){
		$this->display();
	}
	//异步处理文章点击数
	public function addClick(){
	if(!IS_AJAX) E('页面不存在');
    $db = M('blog');
    $id = I('id', '', 'intval');
    $where = array('id'=>$id);
    $db->where($where)->setInc('click', 1);
    $num = $db->where($where)->getField('click');
    echo $num;
	}
}